package com.cs.framework.web.view.support;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cs.framework.core.context.Application;
import com.cs.framework.web.view.View;
import com.cs.framework.web.view.ViewInfo;

/**
 * 请求重定向视图
 * 
 * @author hedongzhou
 * 
 */
public class ReDirectView implements View {

	private final Log logger = LogFactory.getLog(getClass());

	/**
	 * 初始化
	 * 
	 * @param application
	 *            应用上下文
	 */
	public void init(Application application) {
	}

	/**
	 * 渲染视图
	 * 
	 * @param request
	 * @param response
	 * @param viewInfo
	 * @return
	 */
	public ViewInfo render(HttpServletRequest request, HttpServletResponse response, ViewInfo viewInfo) {
		try {
			response.sendRedirect(request.getContextPath() + viewInfo.getViewPath());
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}

		return null;
	}

}
